package com.lw.smartquiz.assess;

import com.lw.smartquiz.common.ErrorCode;
import com.lw.smartquiz.exception.BusinessException;
import com.lw.smartquiz.model.entity.App;
import com.lw.smartquiz.model.entity.UserAnswer;
import com.lw.smartquiz.model.enums.AppTypeEnum;
import com.lw.smartquiz.model.enums.ScoringStrategyEnum;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 评判策略环境类
 * 使用if else来选定策略类，要是增加策略类就需要改逻辑，不符合开闭原则
 */
@Service
@Deprecated
public class AssessStrategyContext {
    @Resource
    private CustomTestAssessStrategy customTestAssessStrategy;
    @Resource
    private CustomScoreAssessStrategy customScoreAssessStrategy;
    @Resource
    private AITestAssessStrategy aiTestAssessStrategy;

    public UserAnswer doScore(List<String> choices, App app) throws Exception {
        AppTypeEnum appTypeEnum = AppTypeEnum.getEnumByValue(app.getAppType());
        ScoringStrategyEnum scoringStrategyEnum = ScoringStrategyEnum.getEnumByValue(app.getScoringStrategy());
        if (appTypeEnum == null || scoringStrategyEnum == null) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "应用类型或评分策略类型错误");
        }

        if (AppTypeEnum.SCORE.equals(appTypeEnum)) {
            if (ScoringStrategyEnum.CUSTOM.equals(scoringStrategyEnum)) {
                return customScoreAssessStrategy.doScore(choices, app);
            } else if (ScoringStrategyEnum.AI.equals(scoringStrategyEnum)) {
                // todo AI评分策略
            } else {
            }
        } else if (AppTypeEnum.TEST.equals(appTypeEnum)) {
            if (ScoringStrategyEnum.CUSTOM.equals(scoringStrategyEnum)) {
                return customTestAssessStrategy.doScore(choices, app);
            } else if (ScoringStrategyEnum.AI.equals(scoringStrategyEnum)) {
                // 测评类应用AI评分策略
                return aiTestAssessStrategy.doScore(choices, app);
            }
        } else {
        }

        throw new BusinessException(ErrorCode.SYSTEM_ERROR, "应用类型或评分策略类型错误");
    }
}
